﻿#include "mainwindow.h"
#include <QApplication>
#include <QAxObject>
#include <QAxWidget>
#include <QVariantList>
#include <QString>
#include <QFile>
#include <QTextStream>
#include <QObject>
#include <QThread>
#include <QDebug>

bool WordStrReplace(const QString& replace_as,const QString replace_to,QAxObject *word){
    QAxObject *select = word->querySubObject("Range()");
    QAxObject *find = select->querySubObject("Find");
    find->dynamicCall("ClearFormatting()");
    find->dynamicCall("Execute(const QString&)",replace_as);
    //select->dynamicCall("Select()");
    return find->setProperty("Text",replace_to);
}


int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    StartDlg *sdlg = new StartDlg;
    MainWindow *w;
    sdlg->show();
    sdlg->setVisible(true);
    a.processEvents();
    QTimer *timer = new QTimer;
//    QThread *thread = new QThread;
    QObject::connect(timer,&QTimer::timeout,[&](){
        timer->stop();
        w = new MainWindow(sdlg);
        w->show();
    });
    timer->start(1000);

//    MainWindow w(sdlg);
//    w.show();
    //delete sdlg;
//    QAxWidget *word = new QAxWidget("Word.Application",0,Qt::MSWindowsOwnDC);
//    word->setProperty("Visible", true);
//    QAxObject *documents = word->querySubObject("Documents");
//    documents->dynamicCall("Open(QString)",QString::fromLocal8Bit("T:\\Lab\1208060160_李日翔_计科122_《汇编》实验报告_1.doc"));
//    QAxObject *document = word->querySubObject("ActiveDocument");
//    QAxObject *cell = document->querySubObject("Tables")
//            ->querySubObject("Item(int)",1)
//            ->querySubObject("Cell(int,int)",2,1)
//            ->querySubObject("Range()");
//    QString ModelName = cell->property("Text").toString().remove(QString::fromLocal8Bit("姓名： "));
//    qDebug()<<cell->property("Text")<<ModelName;
//    cell = document->querySubObject("Tables")
//            ->querySubObject("Item(int)",1)
//            ->querySubObject("Cell(int,int)",2,2)
//            ->querySubObject("Range()");
//    QString ModelNum = cell->property("Text").toString().remove(QString::fromLocal8Bit("学号："));
//    qDebug()<<ModelNum;
//    //document->dynamicCall("Select(void)");
//    QAxObject *sel = document->querySubObject("Range()");
//    //sel->dynamicCall("Select()");
//    QAxObject *find = sel->querySubObject("Find");
//    find->dynamicCall("ClearFormatting()");
//    qDebug()<<find->setProperty("Text","12345");
//    qDebug()<<find->setProperty("Forward",true);
//    qDebug()<<find->setProperty("Wrap",1);
//    qDebug()<<find->setProperty("Format",false);
//    qDebug()<<find->setProperty("MatchCase",false);
//    qDebug()<<find->setProperty("MatchWholeWord",false);
//    qDebug()<<find->setProperty("MatchByte",true);
//    qDebug()<<find->setProperty("MatchWildcards",false);
//    qDebug()<<find->setProperty("MatchSoundsLike",false);
//    qDebug()<<find->setProperty("MatchAllWordForms",false);
//    QAxObject *replacement = find->querySubObject("Replacement");
//    replacement->dynamicCall("ClearFormatting()");
//    qDebug()<<find->property("Text");
//    qDebug()<<replacement->setProperty("Text","1111bbbsasda");
//    qDebug()<<replacement->property("Text");
//    qDebug()<<find->dynamicCall("Execute(const QString&)","1234");
//    sel->dynamicCall("Select()");
//    sel->setProperty("Text","Jakes");
//    qDebug()<<sel->property("Text");
//    document->dynamicCall("SaveAs (const QString&)", QString("P:/docbyqt1.doc"));
    //document->dynamicCall("Close (boolean)", false);
    //word->dynamicCall("Quit()");
//    QString doc = document->generateDocumentation();
//    QFile file("p:/de.html");
//    file.open(QIODevice::WriteOnly|QIODevice::Append);
//    QTextStream ts(&file);
//    ts<<doc<<endl;
    //return 0;
    return a.exec();
}
